package com.qjc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qjc.entity.Position;
import com.qjc.mapper.PositionMapper;
import com.qjc.repository.PositionRepository;
import com.qjc.service.PositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author qjc
 * @since 2022-01-14
 */
@Service
@Slf4j
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {

    @Autowired
    private PositionRepository positionRepository;

    @Override
    public String importData() {
        String result;
        try {
            List<Position> positionList = list(new QueryWrapper<>());
            positionRepository.saveAll(positionList);
            result = "导入数据成功";
        } catch (Exception e) {
            log.error("导入数据出现异常", e);
            result = "导入数据出现异常";
        }
        return result;
    }

    @Override
    public List<Position> queryByPositionName(String positionName) {
        List<Position> positionsByPositionName = positionRepository.findPositionsByPositionName(positionName);
        return positionsByPositionName;
    }
}
